package com.huaxin.device.dto.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 母线材质枚举
 */
public enum BusbarMaterial implements BaseCodeEnum<String> {

    COPPER("copper", "铜"),
    ALUMINUM("aluminum", "铝"),
    SILVER_COATED_COPPER("silver_coated_copper", "镀银铜"),
    TIN_COATED_COPPER("tin_coated_copper", "镀锡铜");

    @EnumValue
    private final String code;
    private final String displayName;

    BusbarMaterial(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static BusbarMaterial of(String code) {
        if (code == null || code.trim().isEmpty()) return null;
        for (BusbarMaterial material : values()) {
            if (material.getCode().equalsIgnoreCase(code.trim())) {
                return material;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }
}